import 'package:amap_flutter_location/amap_flutter_location.dart';
import 'package:base_flutter/pages/index.dart';
import 'package:flutter/material.dart';

import '../common/global.dart';
import '../widgets/modal_widget.dart';
import '../widgets/use_protocol.dart';

class Splash extends StatefulWidget {
  const Splash({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _SplashState();
  }


}
class _SplashState extends State<Splash> {

  @override
  void initState() {
    super.initState();


    if (!Global.agreeClause) {
      Future.delayed(const Duration(milliseconds: 800), () async {
        if (Global.isOther == false) {
          /// MARK --
          AMapFlutterLocation.updatePrivacyShow(true, true);
        }

        double height = MediaQuery.of(context).size.height;
        bool? ret = await ModalWidget.showModal<bool>(context, ConstrainedBox(constraints: BoxConstraints(maxHeight: height * 0.76), child: UseProtocolWidget(),), touchHidden: false);
        if (ret != null && mounted) {

          AMapFlutterLocation.updatePrivacyAgree(true);
          /// 设置key
          Global.settingAmapKey();
          /// 进入首页
          Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context)=> const Index()));
        }
      });
    }

  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    debugInfo('build splash');

    return Material(child: Stack(children: [
      Container(color: Colors.teal, child: Text('初始化页面', style: TextStyle(color: Colors.white),), alignment: Alignment.center,)
    ],),);
  }
}